/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.eng.scc.core.schema.fetcher;

import com.eng.scc.core.data.Company;
import com.eng.scc.core.db.Database;
import com.eng.scc.core.db.Fetcher;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author Rafael
 */
public class CompanyFetcher implements Fetcher<Company>
{
    @Override
    public Company fetch( ResultSet ps ) throws Exception
    {
        Company c = new Company();
        
        c.setId( ps.getInt( 1 ) );
        c.setAddressId( ps.getInt( 2 ) );
        c.setRealName( ps.getString( 3 ) );
        c.setFantasyName( ps.getString( 4 ) );
        c.setCnpj( ps.getString( 5 ) );
        c.setEmail( ps.getString( 6 ) );
        c.setPhone1( ps.getString( 7 ) );
        c.setPhone2( ps.getString( 8 ) );
        c.setState( ps.getShort( 9 ) );
        
        return c;
    }

    @Override
    public void insert( Company value, PreparedStatement ps ) throws Exception
    {
        value.setId( Database.getInstance().nextID( "core_companies" ) );
        
        ps.setInt( 1, value.getId() );
        ps.setInt( 2, value.getAddressId() );
        ps.setString( 3, value.getRealName() );
        ps.setString( 4, value.getFantasyName() );
        ps.setString( 5, value.getCnpj() );
        ps.setString( 6, value.getEmail() );
        ps.setString( 7, value.getPhone1() );
        ps.setString( 8, value.getPhone2() );
        ps.setShort( 9, value.getState() );
    }

    @Override
    public void update( Company value, PreparedStatement ps ) throws Exception
    {
        ps.setInt( 1, value.getAddressId() );
        ps.setString( 2, value.getRealName() );
        ps.setString( 3, value.getFantasyName() );
        ps.setString( 4, value.getCnpj() );
        ps.setString( 5, value.getEmail() );
        ps.setString( 6, value.getPhone1() );
        ps.setString( 7, value.getPhone2() );
        ps.setShort( 8, value.getState() );
        ps.setInt( 9, value.getId() );
    }
    
}
